function calculateNextTimePoint() {
    let startDateTime = new Date(); // 当前时间
    let nWeeks = 2; // 每隔2周
    let dayOfWeek = 2; // 周三
    let hour = 15; // 15点（下午3点）
    let nextTimePoint = this.getNextTimePointWeek(nWeeks, dayOfWeek, hour, startDateTime); // 周
    this.nextTimePoint = nextTimePoint.toLocaleString(); // 格式化显示
    console.log("周", this.nextTimePoint);

    startDateTime = new Date(); // 当前时间
    let daysInterval = 5; // 每隔5天
    let targetHour = 14; // 14点（下午2点）
    nextTimePoint = this.getNextTimePointDay(daysInterval, targetHour, startDateTime); // 天
    this.nextTimePoint = nextTimePoint.toLocaleString(); // 格式化显示
    console.log("天", this.nextTimePoint);

    hour = 3;
    nextTimePoint = this.getNextTimePointHour(hour);  // 时
    this.nextTimePoint = nextTimePoint.toLocaleString(); // 格式化显示
    console.log("时", this.nextTimePoint);
};

/**
 * 
 * @param hoursInterval   // 时  
 * @returns 
 */
function getNextTimePointHour(hoursInterval) {
    // 上述的getNextTimePoint函数实现
    let currentDate = new Date()
    let currentTime = new Date(
        currentDate.getFullYear(),
        currentDate.getMonth(),
        currentDate.getDate(),
        currentDate.getHours(),
        0,
        0,
        0
    );
    let newTime = new Date(currentTime);
    newTime.setHours(currentTime.getHours() + hoursInterval);
    return newTime;
}

/**
 * 
 * @param daysInterval // 天
 * @param targetHour    // 几点
 * @param startDateTime     // 当前时间
 * @returns 
 */
function getNextTimePointDay(daysInterval, targetHour, startDateTime) {
    // 获取当前时间对象
    let currentDate = new Date(startDateTime);

    // 计算第一次目标时间点
    // 设置小时、分钟、秒、毫秒为0，然后加上目标小时
    let firstTargetDate = new Date(
        currentDate.getFullYear(),
        currentDate.getMonth(),
        currentDate.getDate(),
        targetHour,
        0,
        0,
        0
    );

    // 如果今天的时间已经过了今天的目标时间点，则计算到下一个目标时间点
    // if (
    //   currentDate.getHours() > targetHour ||
    //   (currentDate.getHours() === targetHour && currentDate.getMinutes() > 0)
    // ) {
    //   firstTargetDate.setDate(firstTargetDate.getDate() + 1);
    // }

    // 计算每隔daysInterval天后的目标时间点
    let resultDate = new Date(firstTargetDate);
    resultDate.setDate(firstTargetDate.getDate() + daysInterval);

    return resultDate;
};

/**
 * 
 * @param nWeeks    // 每隔几周
 * @param dayOfWeek   // 周几
 * @param {*} hour    // 几点
 * @param {*} startDateTime     // 当前时间
 * @returns 
 */
function getNextTimePointWeek(nWeeks, dayOfWeek, hour, startDateTime) {
    // 上述的getNextTimePoint函数实现
    let currentDate = new Date(startDateTime);
    let currentDayOfWeek = currentDate.getDay();
    let daysUntilNextTargetDay =
        dayOfWeek >= currentDayOfWeek
            ? dayOfWeek - currentDayOfWeek
            : dayOfWeek + 7 - currentDayOfWeek;
    let firstTargetDate = new Date(currentDate);
    firstTargetDate.setDate(currentDate.getDate() + daysUntilNextTargetDay);
    firstTargetDate.setHours(hour, 0, 0, 0);

    if (
        currentDate.getHours() > hour ||
        (currentDate.getHours() === hour && currentDate.getMinutes() > 0)
    ) {
        firstTargetDate.setDate(firstTargetDate.getDate() + 7);
    }

    let resultDate = new Date(firstTargetDate);
    resultDate.setDate(firstTargetDate.getDate() + nWeeks * 7);

    return resultDate;
}

export {
    getNextTimePointHour,   // 时
    getNextTimePointDay,    // 天
    getNextTimePointWeek,   // 周
}